{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From /home/xieyipeng/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/compat/v2_compat.py:65: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "non-resource variables are not supported in the long term\n"
     ]
    }
   ],
   "source": [
    "import h5py\n",
    "import matplotlib.pyplot as plt\n",
    "from tensorflow.python.framework import ops\n",
    "from do_not_src.week3.da import tf_utils\n",
    "import tensorflow.compat.v1 as tf\n",
    "import time\n",
    "import numpy as np\n",
    "tf.disable_v2_behavior()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n"
     ]
    }
   ],
   "source": [
    "y_hat = tf.constant(36,name=\"y_hat\")            #定义y_hat为固定值36\n",
    "y = tf.constant(39,name=\"y\")                    #定义y为固定值39\n",
    "\n",
    "loss = tf.Variable((y-y_hat)**2,name=\"loss\" )   #为损失函数创建一个变量\n",
    "\n",
    "init = tf.global_variables_initializer()        #运行之后的初始化(ession.run(init))\n",
    "                                                #损失变量将被初始化并准备计算\n",
    "with tf.Session() as session:                   #创建一个session并打印输出\n",
    "    session.run(init)                           #初始化变量\n",
    "    print(session.run(loss))                    #打印损失值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tensor(\"Mul:0\", shape=(), dtype=int32)\n"
     ]
    }
   ],
   "source": [
    "a = tf.constant(2)\n",
    "b = tf.constant(10)\n",
    "c = tf.multiply(a,b)\n",
    "\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20\n"
     ]
    }
   ],
   "source": [
    "sess = tf.Session()\n",
    "\n",
    "print(sess.run(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "#利用feed_dict来改变x的值\n",
    "\n",
    "x = tf.placeholder(tf.int64,name=\"x\")\n",
    "print(sess.run(2 * x,feed_dict={x:3}))\n",
    "sess.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def linear_function():\n",
    "    \"\"\"\n",
    "    实现一个线性功能：\n",
    "        初始化W，类型为tensor的随机变量，维度为(4,3)\n",
    "        初始化X，类型为tensor的随机变量，维度为(3,1)\n",
    "        初始化b，类型为tensor的随机变量，维度为(4,1)\n",
    "    返回：\n",
    "        result - 运行了session后的结果，运行的是Y = WX + b \n",
    "    \n",
    "    \"\"\"\n",
    "    \n",
    "    np.random.seed(1) #指定随机种子\n",
    "    \n",
    "    X = np.random.randn(3,1)\n",
    "    W = np.random.randn(4,3)\n",
    "    b = np.random.randn(4,1)\n",
    "    \n",
    "    Y = tf.add(tf.matmul(W,X),b) #tf.matmul是矩阵乘法\n",
    "    #Y = tf.matmul(W,X) + b #也可以以写成这样子\n",
    "    \n",
    "    #创建一个session并运行它\n",
    "    sess = tf.Session()\n",
    "    result = sess.run(Y)\n",
    "    \n",
    "    #session使用完毕，关闭它\n",
    "    sess.close()\n",
    "    \n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "result = [[-2.15657382]\n",
      " [ 2.95891446]\n",
      " [-1.08926781]\n",
      " [-0.84538042]]\n"
     ]
    }
   ],
   "source": [
    "print(\"result = \" +  str(linear_function()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sigmoid(z):\n",
    "    \"\"\"\n",
    "    实现使用sigmoid函数计算z\n",
    "    \n",
    "    参数：\n",
    "        z - 输入的值，标量或矢量\n",
    "    \n",
    "    返回：\n",
    "        result - 用sigmoid计算z的值\n",
    "    \n",
    "    \"\"\"\n",
    "    \n",
    "    #创建一个占位符x，名字叫“x”\n",
    "    x = tf.placeholder(tf.float32,name=\"x\")\n",
    "    \n",
    "    #计算sigmoid(z)\n",
    "    sigmoid = tf.sigmoid(x)\n",
    "    \n",
    "    #创建一个会话，使用方法二\n",
    "    with tf.Session() as sess:\n",
    "        result = sess.run(sigmoid,feed_dict={x:z})\n",
    "        \n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sigmoid(0) = 0.5\n",
      "sigmoid(12) = 0.9999938\n"
     ]
    }
   ],
   "source": [
    "print (\"sigmoid(0) = \" + str(sigmoid(0)))\n",
    "print (\"sigmoid(12) = \" + str(sigmoid(12)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def one_hot_matrix(lables,C):\n",
    "    \"\"\"\n",
    "    创建一个矩阵，其中第i行对应第i个类号，第j列对应第j个训练样本\n",
    "    所以如果第j个样本对应着第i个标签，那么entry (i,j)将会是1\n",
    "    \n",
    "    参数：\n",
    "        lables - 标签向量\n",
    "        C - 分类数\n",
    "        \n",
    "    返回：\n",
    "        one_hot - 独热矩阵\n",
    "    \n",
    "    \"\"\"\n",
    "    \n",
    "    #创建一个tf.constant，赋值为C，名字叫C\n",
    "    C = tf.constant(C,name=\"C\")\n",
    "    \n",
    "    #使用tf.one_hot，注意一下axis\n",
    "    one_hot_matrix = tf.one_hot(indices=lables , depth=C , axis=0)\n",
    "    \n",
    "    #创建一个session\n",
    "    sess = tf.Session()\n",
    "    \n",
    "    #运行session\n",
    "    one_hot = sess.run(one_hot_matrix)\n",
    "    \n",
    "    #关闭session\n",
    "    sess.close()\n",
    "    \n",
    "    return one_hot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0. 0. 0. 1. 0. 0.]\n",
      " [1. 0. 0. 0. 0. 1.]\n",
      " [0. 1. 0. 0. 1. 0.]\n",
      " [0. 0. 1. 0. 0. 0.]]\n"
     ]
    }
   ],
   "source": [
    "labels = np.array([1,2,3,0,2,1])\n",
    "one_hot = one_hot_matrix(labels,C=4)\n",
    "print(str(one_hot))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def ones(shape):\n",
    "    \"\"\"\n",
    "    创建一个维度为shape的变量，其值全为1\n",
    "    \n",
    "    参数：\n",
    "        shape - 你要创建的数组的维度\n",
    "    \n",
    "    返回：\n",
    "        ones - 只包含1的数组    \n",
    "    \"\"\"\n",
    "    \n",
    "    #使用tf.ones()\n",
    "    ones = tf.ones(shape)\n",
    "    \n",
    "    #创建会话\n",
    "    sess = tf.Session()\n",
    "    \n",
    "    #运行会话\n",
    "    ones = sess.run(ones)\n",
    "    \n",
    "    #关闭会话\n",
    "    sess.close()\n",
    "    \n",
    "    return ones"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ones = [1. 1. 1.]\n"
     ]
    }
   ],
   "source": [
    "print (\"ones = \" + str(ones([3])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train_orig , Y_train_orig , X_test_orig , Y_test_orig , classes = tf_utils.load_dataset()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Y = 1\n"
     ]
    },
    {
     "data": {
      "image/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bt8Nggq7DqAP3TO3QjgLgCfbF+Dfs+lAuAe59y7AdwK4F4iugvA5wF8oT2PBQD3X+V5bOJTaNGTb2JQ83i/c+5WZuoaxDNy9WjbnXN9+QPwHgB/x44/C+CzfRz/OIBn2fGLAA62ywcBvNivubA5PALgg4OcC4BRAD8BcCdazhuFbvfrKo5/pP0A3wPg22gFDwxiHq8B2BN81tf7AmACwKto76Xt9jz6KcYfBvAmO55rfzYoDJQKm4iOA7gNwJODmEtbdH4aLaLQxwD8EsCicx3mhn7dny8C+CP4GJDZAc3DAfgOEf2YiB5of9bv+3JVadv7udi7hXtl0hRARGMA/grAHzjnBsKv7ZxrOOduRevNegeAG7s1u5pzIKLfAXDBOfdj/nG/59HGe51zt6OlZn6SiN7XhzFD7Ii2fSv0c7HPATjKjo8AONPH8UOkosLebRBREa2F/lXn3DcHORcAcM4topXN5y4AU0S0Gfbcj/vzXgAfIaLXADyMlij/xQHMA865M+3/FwB8C60fwH7flx3Rtm+Ffi72pwCcaO+0DgH4XQCP9nH8EI+iRYENpKTC3imoFYz/ZQCnnXN/Oqi5ENFeIppql0cA/DZaG0HfBfCxfs3DOfdZ59wR59xxtJ6Hv3fO/X6/50FEZSIa3ywD+BCAZ9Hn++KcOwfgTSK6of3RJm377szjam98BBsNHwbwC7T0w//Ux3H/AsBZADW0fj3vR0s3fBzAS+3/M32Yx2+hJZL+DMDT7b8P93suAG4B8NP2PJ4F8J/bn18H4EcAXgbwlwCG+3iP7gbw7UHMoz3eM+2/5zafzQE9I7cCONW+N38NYHq35mEedAZDRmAedAZDRmCL3WDICGyxGwwZgS12gyEjsMVuMGQEttgNhozAFrvBkBHYYjcYMoL/D0lylXgE6XIJAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "index = 11\n",
    "plt.imshow(X_train_orig[index])\n",
    "print(\"Y = \" + str(np.squeeze(Y_train_orig[:,index])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集样本数 = 1080\n",
      "测试集样本数 = 120\n",
      "X_train.shape: (12288, 1080)\n",
      "Y_train.shape: (6, 1080)\n",
      "X_test.shape: (12288, 120)\n",
      "Y_test.shape: (6, 120)\n"
     ]
    }
   ],
   "source": [
    "X_train_flatten = X_train_orig.reshape(X_train_orig.shape[0],-1).T #每一列就是一个样本\n",
    "X_test_flatten = X_test_orig.reshape(X_test_orig.shape[0],-1).T\n",
    "\n",
    "#归一化数据\n",
    "X_train = X_train_flatten / 255\n",
    "X_test = X_test_flatten / 255\n",
    "\n",
    "#转换为独热矩阵\n",
    "Y_train = tf_utils.convert_to_one_hot(Y_train_orig,6)\n",
    "Y_test = tf_utils.convert_to_one_hot(Y_test_orig,6)\n",
    "\n",
    "print(\"训练集样本数 = \" + str(X_train.shape[1]))\n",
    "print(\"测试集样本数 = \" + str(X_test.shape[1]))\n",
    "print(\"X_train.shape: \" + str(X_train.shape))\n",
    "print(\"Y_train.shape: \" + str(Y_train.shape))\n",
    "print(\"X_test.shape: \" + str(X_test.shape))\n",
    "print(\"Y_test.shape: \" + str(Y_test.shape))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def create_placeholders(n_x,n_y):\n",
    "    \"\"\"\n",
    "    为TensorFlow会话创建占位符\n",
    "    参数：\n",
    "        n_x - 一个实数，图片向量的大小（64*64*3 = 12288）\n",
    "        n_y - 一个实数，分类数（从0到5，所以n_y = 6）\n",
    "    \n",
    "    返回：\n",
    "        X - 一个数据输入的占位符，维度为[n_x, None]，dtype = \"float\"\n",
    "        Y - 一个对应输入的标签的占位符，维度为[n_Y,None]，dtype = \"float\"\n",
    "    \n",
    "    提示：\n",
    "        使用None，因为它让我们可以灵活处理占位符提供的样本数量。事实上，测试/训练期间的样本数量是不同的。\n",
    "    \n",
    "    \"\"\"\n",
    "    \n",
    "    X = tf.placeholder(tf.float32, [n_x, None], name=\"X\")\n",
    "    Y = tf.placeholder(tf.float32, [n_y, None], name=\"Y\")\n",
    "    \n",
    "    return X, Y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "X = Tensor(\"X_3:0\", shape=(12288, ?), dtype=float32)\n",
      "Y = Tensor(\"Y_1:0\", shape=(6, ?), dtype=float32)\n"
     ]
    }
   ],
   "source": [
    "X, Y = create_placeholders(12288, 6)\n",
    "print(\"X = \" + str(X))\n",
    "print(\"Y = \" + str(Y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "W1 = tf.get_variable(\"W1\", [25,12288], initializer =  tf.truncated_normal_initializer(stddev=0.1))\n",
    "b1 = tf.get_variable(\"b1\", [25,1], initializer = tf.zeros_initializer())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "def initialize_parameters():\n",
    "    \"\"\"\n",
    "    初始化神经网络的参数，参数的维度如下：\n",
    "        W1 : [25, 12288]\n",
    "        b1 : [25, 1]\n",
    "        W2 : [12, 25]\n",
    "        b2 : [12, 1]\n",
    "        W3 : [6, 12]\n",
    "        b3 : [6, 1]\n",
    "    \n",
    "    返回：\n",
    "        parameters - 包含了W和b的字典\n",
    "    \n",
    "    \n",
    "    \"\"\"\n",
    "    \n",
    "    tf.set_random_seed(1) #指定随机种子\n",
    "    \n",
    "    W1 = tf.get_variable(\"W1\",[25,12288],initializer=tf.contrib.layers.xavier_initializer(seed=1))\n",
    "    b1 = tf.get_variable(\"b1\",[25,1],initializer=tf.zeros_initializer())\n",
    "    W2 = tf.get_variable(\"W2\", [12, 25], initializer = tf.contrib.layers.xavier_initializer(seed=1))\n",
    "    b2 = tf.get_variable(\"b2\", [12, 1], initializer = tf.zeros_initializer())\n",
    "    W3 = tf.get_variable(\"W3\", [6, 12], initializer = tf.contrib.layers.xavier_initializer(seed=1))\n",
    "    b3 = tf.get_variable(\"b3\", [6, 1], initializer = tf.zeros_initializer())\n",
    "    \n",
    "    parameters = {\"W1\": W1,\n",
    "                  \"b1\": b1,\n",
    "                  \"W2\": W2,\n",
    "                  \"b2\": b2,\n",
    "                  \"W3\": W3,\n",
    "                  \"b3\": b3}\n",
    "    \n",
    "    return parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'tensorflow_core.compat.v1' has no attribute 'contrib'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-23-953bb7e8bcc1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mSession\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0msess\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m     \u001b[0mparameters\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0minitialize_parameters\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      5\u001b[0m     \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"W1 = \"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mparameters\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"W1\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      6\u001b[0m     \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"b1 = \"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mparameters\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"b1\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-22-4fbc1e31ccc7>\u001b[0m in \u001b[0;36minitialize_parameters\u001b[0;34m()\u001b[0m\n\u001b[1;32m     17\u001b[0m     \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_random_seed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m#指定随机种子\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     18\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 19\u001b[0;31m     \u001b[0mW1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_variable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"W1\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m25\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m12288\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0minitializer\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcontrib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlayers\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mxavier_initializer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mseed\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     20\u001b[0m     \u001b[0mb1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_variable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"b1\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m25\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0minitializer\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros_initializer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     21\u001b[0m     \u001b[0mW2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_variable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"W2\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m12\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m25\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minitializer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcontrib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlayers\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mxavier_initializer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mseed\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mAttributeError\u001b[0m: module 'tensorflow_core.compat.v1' has no attribute 'contrib'"
     ]
    }
   ],
   "source": [
    "tf.reset_default_graph() #用于清除默认图形堆栈并重置全局默认图形。 \n",
    "\n",
    "with tf.Session() as sess:\n",
    "    parameters = initialize_parameters()\n",
    "    print(\"W1 = \" + str(parameters[\"W1\"]))\n",
    "    print(\"b1 = \" + str(parameters[\"b1\"]))\n",
    "    print(\"W2 = \" + str(parameters[\"W2\"]))\n",
    "    print(\"b2 = \" + str(parameters[\"b2\"]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
